package com.icoolkj.ms.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/02/12 18:45
 */
@Component
public class CustomGlobalFilter implements GlobalFilter, Ordered {


    @Override
    public int getOrder() {
        // 设置过滤器的执行顺序，越小越先执行
        return -1;
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 打印日志确认过滤器被调用
        System.out.println("Global filter intercepted: " + exchange.getRequest().getURI());

        // 放行请求
        return chain.filter(exchange);
    }
}
